<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<jsp:include page="/common/commonCss.jsp"/>
<jsp:include page="/common/commonJs.jsp"/>
<script  language="javascript" src="${basePath}commonJs/jquery.ztree.all.js"></script>
<script language="javascript" src="${basePath }commonJs/verify.js"></script>
<title>嘉童游乐中心-商品信息</title>
</head>
	<SCRIPT type="text/javascript">
		var selectNode=null;
		var treeNodes=[];
		var tableId="";
		var cateId="";
		var branId="${branId}";
		var nowBranId="${isHead}";
		var addFlag;//总部人员是否具有定价按钮的权限
		var deleteFlag;//删除权限
		var updateFlag;//修改权限
		var approveFlag;//审批总部定价的权限
		var  reviewFlag;//总部重新定价的权限
		var addFlagForBranch;//分店人员是否具有定价按钮的权限
		var setting = {
			data: {
				simpleData: {
					enable: true
				}
			},
			callback:{
				onClick:zTreeOnClick
			}
		};
		/*得到商品分类的数据信息*/
		function   getTreeData(){
					$.ajax({
							url:"${basePath}scmInvocing/priceManager/findCategoryList.shtml",
							dataType:"json",
							type:"post",
		      	 			async:false,
		      	 			error : function(XMLHttpRequest) {
		      	 				ajaxError(XMLHttpRequest);
		      	 			},
		      	 			success:function(result){
		      	 				var node;
		      	 				$(result).each(function(id,item){
		      	 					if(id==0){
			      	 					node={id:item.pkPrdcateId,pId:item.fkParPrdcateId,name:item.cateName,open:true,reserveFlag:item.reserveFlag,resverseType:item.resverseType};
		      	 					}else{
			      	 					node={id:item.pkPrdcateId,pId:item.fkParPrdcateId,name:item.cateName,reserveFlag:item.reserveFlag,resverseType:item.resverseType};
		      	 					}
		      	 					treeNodes.push(node);
		      	 				});
		      	 			}
					});
		}
		$(document).ready(function(){
			getTreeData();
			$.fn.zTree.init($("#sptree"), setting, treeNodes);
			setDefaultForTree();
			//验证当前登录用户是否可以操作总部的定价数据
		    addFlag=isVerify("${basePath}", "price:add");
		    deleteFlag=isVerify("${basePath}", "price:delete");
		    updateFlag=isVerify("${basePath}", "price:update");
		    approveFlag=isVerify("${basePath}", "price:approve");
		    reviewFlag=isVerify("${basePath}", "price:review");
		    addFlagForBranch=isVerify("${basePath}", "price:addForBranch"); 
			//获取当前门店的定价信息
			loadPage(false);
		});
		//设置ztrre默认选中,以及样式
		function setDefaultForTree(){
			$("#sptree_1_a").addClass("curSelectedNode");
			selectNode=treeNodes[0];
			cateId="";
		}
		//页面加载时执行默认的分页查询方法
		function loadPage(isSearch){
			var id=$(".thistab_a").attr("id").split("_")[0];
			var form = $("#" + id+"Form");
			tableId=id+"Table";
			if(isSearch){
				var pkPrdId=$("#pkPrdId").val();
				var prdName=$("#prdName").val();
				form.find("input:[name='pkPrdId']").val(pkPrdId);
				form.find("input:[name='prdName']").val(prdName);
			}
			form.find("input:[name='cateId']").val(cateId);
			form.find("input:[name='pageNo']").val("1");
			form.find("input:[name='pageSize']").val("8");
			var pagebean = new PageBean(form);
			pagebean.setTableId(tableId);
			pagebean.setFootId(id+"Foot");
			if(id=="ZB"){
				pagebean.setCallback(showHeadData);
			}else{
				pagebean.setCallback(showBranchData);
			}
			setPagebeanObj(pagebean);
			pagebean.doPage();
		}
		//根据搜索条件查询
		function findPriceInfo(){
			loadPage(true);
		}
		function zTreeOnClick(event, treeId, treeNode) {
			var tId=treeNode.tId;
			if(tId!="sptree_1"){
				$("#sptree_1_a").removeClass("curSelectedNode");
			}
			selectNode = treeNode;//  每次点击赋值 
			cateId=selectNode.id;
			loadPage(true);
			
		};
		//设定分页的数据
		function initTable(obj){
			var pkPrdId=$("#pkPrdId").val();
			var prdName=$("#prdName").val();
			var formId=$(obj).attr("id").split("_")[0];
			var branChFlag=$(obj).attr("branChFlag");
			var form = $("#" + formId+"Form");
			tableId=formId+"Table";
			form.find("input:[name='pkPrdId']").val(pkPrdId);
			form.find("input:[name='prdName']").val(prdName);
			form.find("input:[name='cateId']").val(cateId);
			//初始化
			form.find("input:[name='pageNo']").val("1");
			form.find("input:[name='pageSize']").val("8");
			var pagebean = new PageBean(form);
			pagebean.setTableId(tableId);
			pagebean.setFootId(formId+"Foot");
			if(branChFlag=="ZB"){
				pagebean.setCallback(showHeadData);
			}else{
				pagebean.setCallback(showBranchData);
			}
			setPagebeanObj(pagebean);
			pagebean.doPage();
		}
		
		function readHeadInfo(thisObj){
			var pkPrdId=$(thisObj).attr("id");
			window.location.href="${basePath}scmInvocing/priceManager/readHeadInfo.shtml?pkPrdId="+pkPrdId+"";
			
		}
		//显示总部的数据
		function showHeadData(result){
			var  obj=result[0];
			var  isBoss=result[1];
			trimJsonArray(obj);
			$(obj).each(function(index,item){
				var html=""; 
				html+='<tr><td class="lv">_href_option</td>';
				if(item.prdName.length>4){
					html+='<td title="'+item.prdName+'">'+item.prdName.substring(0,4)+'...</td> ';
				}else{
					html+='<td>'+item.prdName+'</td> ';
				}
				html+=' <td>'+item.prdSpec+'</td>';
				html+='<td>'+item.unitName+'</td>';
				html+='<td>'+item.marketPrice+'</td>';
				html+='<td>'+item.headPrice+'</td>';
				if(item.isAllow=="1"){
					html+='<td>是</td>';
				}else if(item.isAllow=="0"){
					html+='<td>否</td>';
				}else{
					html+='<td></td>';
				}
				html+='<td>_status_desc</td>';
				html+='<td>_option_button</td></tr>';
				if(item.status=="2"){//草稿
					html=html.replace("_status_desc",'草稿'); 
					if(updateFlag==true){
						html=html.replace("_href_option", '<a href="#" id='+item.pkPrdId+' isNew="n"   onclick="editForHead(this);">'+item.pkPrdId+'</a>');
						html=html.replace("_option_button",'<input type="button"  value="编辑"  id='+item.pkPrdId+'  isNew="n"  onclick="editForHead(this);"  class="btn_l">');
					}else{
						html=html.replace("_href_option", '<a href="#" id='+item.pkPrdId+'   onclick="readHeadInfo(this);">'+item.pkPrdId+'</a>');
						html=html.replace("_option_button",'');
					}
				}else if(item.status=="3"){
					 html=html.replace("_status_desc",'待复核'); 
					 if(approveFlag==true){
						 html=html.replace("_href_option", '<a href="#" id='+item.pkPrdId+' isNew="n"  onclick="reviewPriceForHead(this);">'+item.pkPrdId+'</a>');
						 html=html.replace("_option_button", '<input type="button"  value="处理"   id='+item.pkPrdId+' onclick="reviewPriceForHead(this);"  class="btn_l" >');
					 }else{
							html=html.replace("_href_option", '<a href="#" id='+item.pkPrdId+'   onclick="readHeadInfo(this);">'+item.pkPrdId+'</a>');
							html=html.replace("_option_button",'');
					 }
				}else if(item.status=="4"){
					html=html.replace("_status_desc",'复核不通过');
					if(reviewFlag==true){
						 html=html.replace("_href_option", '<a href="#" id='+item.pkPrdId+' isNew="n"  onclick="reSubmitForHead(this);">'+item.pkPrdId+'</a>');
						 html=html.replace("_option_button",'<input type="button" class="btn_l" value="重新提交"  id='+item.pkPrdId+' onclick="reSubmitForHead(this);"  pkPriceId='+item.pkPriceId+' />');
					}else{
						html=html.replace("_href_option", '<a href="#" id='+item.pkPrdId+'   onclick="readHeadInfo(this);">'+item.pkPrdId+'</a>');
						html=html.replace("_option_button",'');
					}
				}else if(item.status=="1"){
					html=html.replace("_status_desc",'复核通过');
					if(addFlag==true){
						 html=html.replace("_href_option", '<a href="#" id='+item.pkPrdId+' isNew="y"  onclick="editForHead(this);">'+item.pkPrdId+'</a>');
						 html=html.replace("_option_button",'<input type="button" class="btn_l" value="重新定价"  id='+item.pkPrdId+'  isNew="y"   pkPriceId='+item.pkPriceId+'   onclick="editForHead(this);"><input type="button" class="btn_l ml10" value="历史定价" id='+item.pkPrdId+' onclick="historyForHead(this);">');
					}else{
						html=html.replace("_href_option", '<a href="#" id='+item.pkPrdId+'   onclick="readHeadInfo(this);">'+item.pkPrdId+'</a>');
						html=html.replace("_option_button",'<input type="button" class="btn_l ml10" value="历史定价" id='+item.pkPrdId+' onclick="historyForHead(this);">');
					}
				  }else{
					html=html.replace("_status_desc",'');
					if(addFlag==true){
						 	html=html.replace("_href_option", '<a href="#" id='+item.pkPrdId+' isNew="n"  onclick="setPriceForHead(this);">'+item.pkPrdId+'</a>');
							html=html.replace("_option_button",'<input type="button"  value="定价"    id='+item.pkPrdId+' onclick="setPriceForHead(this);"  class="btn_l">');
					}else{
						html=html.replace("_href_option", '<a href="#" id='+item.pkPrdId+'   onclick="readHeadInfo(this);">'+item.pkPrdId+'</a>');
						html=html.replace("_option_button",'');
					}
				  }
					$("#"+tableId).find("tr:eq("+index+")").after(html);
			});
		}
		function initTable(obj){
			var pkPrdId=$("#pkPrdId").val();
			var prdName=$("#prdName").val();
			var formId=$(obj).attr("id").split("_")[0];
			var branChFlag=$(obj).attr("branChFlag");
			var form = $("#" + formId+"Form");
			tableId=formId+"Table";
			form.find("input:[name='pkPrdId']").val(pkPrdId);
			form.find("input:[name='prdName']").val(prdName);
			form.find("input:[name='cateId']").val(cateId);
			//初始化
			form.find("input:[name='pageNo']").val("1");
			form.find("input:[name='pageSize']").val("8");
			var pagebean = new PageBean(form);
			pagebean.setTableId(tableId);
			pagebean.setFootId(formId+"Foot");
			if(branChFlag=="ZB"){
				pagebean.setCallback(showHeadData);
			}else{
				pagebean.setCallback(showBranchData);
			}
			setPagebeanObj(pagebean);
			pagebean.doPage();
		}
		//总部的商品历史定价信息
		function historyForHead(thisObj){
			var id=$(thisObj).attr("id");
			$("#historyHead").window('open');
			initParams(id);
		}
		//初始化参数
		function initParams(id) {
			$("#fkPrdId").val(id);
			$("#pageNoForHead").val("1");
			var myform = $("#historyForm");
			var pagebean = new PageBean(myform);
			pagebean.setTableId("historyData");
			pagebean.setFootId("foot");
			pagebean.setCallback(showHistoryForHead);
			setPagebeanObj(pagebean); //全局化pageBean对象
			pagebean.doPage();//执行分页
		}
		//显示总部的历史定价信息
		function showHistoryForHead(result){
				trimJsonArray(result);
		         $(result).each(function(id,item){
		        	 var html="<tr><td>"+(id+1)+"</td>";
		        	 html+="<td>"+item.userName+"</td>";
		        	 html+="<td>"+item.marketPrice+"</td>";
		        	 html+="<td>"+item.headPrice+"</td>";
		        	 html+="<td>"+item.orderTime+"</td>";
		        	$("#historyData").find("tr:eq("+id+")").after(html);
		         });
		        var first=result[0];
		        if(first!=null){
		        	$("#headPrdName").html(first.prdName);
		        	$("#headPrdSpec").html(first.prdSpec);
		        	$("#headUnitName").html(first.unitName);
		        }
		}
		//显示门店的历史定价数据
		function showHistoryForBranch(thisObj){
			var fkBranId=$(".thistab_a").attr("id").split("_")[0];
		    var fkPrdId=$(thisObj).attr("pkPrdId");
		    $("#historyBranch").window('open');
		   	initHistoryForBranch(fkPrdId, fkBranId);
		}
		function initHistoryForBranch(fkPrdId,fkBranId){
			$("#fkBranId").val(fkBranId);
			$("#PrdId").val(fkPrdId);
			$("#pageNo").val("1");
			$("#pageSize").val("8");
			var myform = $("#historyForBranch");
			var pagebean = new PageBean(myform);
			pagebean.setTableId("historyBranchTable");
			pagebean.setFootId("footForBranch");
			pagebean.setCallback(showHistoryData);
			setPagebeanObj(pagebean); //全局化pageBean对象
			pagebean.doPage();//执行分页
			
		}
		//显示门店历史定价信息
		function showHistoryData(result){
			trimJsonArray(result);
	         $(result).each(function(id,item){
	        	 var html="<tr><td>"+(id+1)+"</td>";
	        	 html+="<td>"+item.userName+"</td>";
	        	 html+="<td>"+item.marketPrice+"</td>";
	        	 html+="<td>"+item.branchPrice+"</td>";
	        	 html+="<td>"+item.orderTime+"</td>";
	        	$("#historyBranchTable").find("tr:eq("+id+")").after(html);
	         });
	        var first=result[0];
	        if(first!=null){
	        	$("#prdNameForBranch").html(first.prdName);
	        	$("#prdSpecForBranch").html(first.prdSpec);
	        	$("#unitNameForBranch").html(first.unitName);
	        }
		}
		//显示分店的数据
		function  showBranchData(resultList){
			//trimJsonArray(resultList);
			var  result=resultList[0];
			var isBoss=resultList[1];//是否为运营总监
			var isManager=resultList[2];//是否为门店经理
			trimJsonArray(result);
			var html="";
			  //总部登录看分店数据
			if(branId=="ZB"){
			$(result).each(function(index,item){
					    	var 	obj2=item.workflowVo;
					    	html='<tr><td class="lv">_option_href</td>';
							 if(item.prdName.length>4){
				       			  html+='<td title='+item.prdName+'>'+item.prdName.substring(0,4)+'...</td>';
				       		 }else{
				       			  html+='<td>'+item.prdName+'</td>';
				       		 }
				             html+='<td>'+item.prdSpec+'</td>';
				             html+='<td>'+item.unitName+'</td>'; 
				             html+='<td>'+item.marketPrice+'</td>';
				             html+='<td>'+item.headPrice+'</td>';
				             if(item.isAllow=="1"){
									html+='<td>是</td>';
							}else if(item.isAllow=="0"){
									html+='<td>否</td>';
							}else{
									html+='<td></td>';
							}
				             html+='<td>'+item.branchPrice+'</td>';
				             html+='<td>_status_desc</td>';
			            	 html+='<td>_status_result</td>';
				             html+='<td>_option_button</td></tr>';
		            	 if(item.status=="1"){
		            		 html=html.replace("_option_href", '<a href="#"   pkPriceId="'+item.pkPriceId+'"  pkPrdId="'+item.pkPrdId+'"   onclick="readBranchInfo(this);" >'+item.pkPrdId+'</a>');
		                	 html=html.replace("_option_button", '');
		                	 html=html.replace("_status_desc", "草稿");
		                	 html=html.replace("_status_result", "");
		                 }else if(item.status=="2"){
		                	 if(isBoss=="1"&&obj2.isStartUser!="1"){
			            		 html=html.replace("_option_href", '<a href="#"   pkPriceId="'+item.pkPriceId+'"  pkPrdId="'+item.pkPrdId+'"   onclick="handleBranchPrice(this);" >'+item.pkPrdId+'</a>');
			                	 html=html.replace("_option_button", '<input type="button"   value="处理"  pkPriceId="'+item.pkPriceId+'"  pkPrdId="'+item.pkPrdId+'"   onclick="handleBranchPrice(this);"   class="btn_l">');
		                	 }else{
			            		 html=html.replace("_option_href", '<a href="#"   pkPriceId="'+item.pkPriceId+'"  pkPrdId="'+item.pkPrdId+'"   onclick="readBranchInfo(this);" >'+item.pkPrdId+'</a>');
			                	 html=html.replace("_option_button", '');
		                	 }
		                	 html=html.replace("_status_desc", obj2.statusDesc);
		                	 html=html.replace("_status_result",obj2.result==null?"":obj2.result);
		                 }else if(item.status=="3"){
		                	 html=html.replace("_option_href", '<a href="#"   pkPriceId="'+item.pkPriceId+'"  pkPrdId="'+item.pkPrdId+'"   onclick="readBranchInfo(this);" >'+item.pkPrdId+'</a>');
		                	 html=html.replace("_option_button", '<input type="button" onclick="showHistoryForBranch(this);" pkPrdId="'+item.pkPrdId+'"   value="历史定价" class="btn_l ml10">');
		                	 html=html.replace("_status_desc", obj2.statusDesc);
		                	 html=html.replace("_status_result",obj2.result==null?"":obj2.result);
		                 }else if(item.status=="4"){
			               	 html=html.replace("_option_href", '<a href="#"   pkPriceId="'+item.pkPriceId+'"  pkPrdId="'+item.pkPrdId+'"   onclick="readBranchInfo(this);" >'+item.pkPrdId+'</a>');
		                	 html=html.replace("_option_button", '<input type="button" onclick="showHistoryForBranch(this);" pkPrdId="'+item.pkPrdId+'"   value="历史定价" class="btn_l ml10">');
		                	 html=html.replace("_status_desc", obj2.statusDesc);
		                	 html=html.replace("_status_result",obj2.result==null?"":obj2.result);
		                 }else if(item.status=="5"){
		                	 html=html.replace("_option_href", '<a href="#"   pkPriceId="'+item.pkPriceId+'"  pkPrdId="'+item.pkPrdId+'"   onclick="readBranchInfo(this);" >'+item.pkPrdId+'</a>');
		                	 html=html.replace("_option_button", '');
		                	 html=html.replace("_status_desc", obj2.statusDesc);
		                	 html=html.replace("_status_result",obj2.result==null?"":obj2.result);
		                 }else{
		                	 html=html.replace("_option_href", '<a href="#"   pkPriceId="'+item.pkPriceId+'"  pkPrdId="'+item.pkPrdId+'"   onclick="readBranchInfo(this);" >'+item.pkPrdId+'</a>');
		                	 html=html.replace("_option_button", '');
		                	 html=html.replace("_status_desc", "");
		                	 html=html.replace("_status_result","");
		                 }
		          $("#"+tableId).find("tr:eq("+index+")").after(html);
				}); 
             }else{
            	 $(result).each(function(index,item){
            		 var  obj2=item.workflowVo;
            		 html='<tr><td class="lv">_option_href</td>';
            		 if(item.prdName.length>4){
           			 	 html+='<td title='+item.prdName+'>'+item.prdName.substring(0,4)+'...</td>';
           			 }else{
           			  	html+='<td>'+item.prdName+'</td>';
           			 }
                    html+='<td>'+item.prdSpec+'</td>';
                    html+='<td>'+item.unitName+'</td>'; 
                    html+='<td>'+item.marketPrice+'</td>';
                    html+='<td>'+item.headPrice+'</td>';
                    if(item.isAllow=="1"){
       					html+='<td>是</td>';
       				}else if(item.isAllow=="0"){
       					html+='<td>否</td>';
       				}else{
       					html+='<td></td>';
       				}
                    html+='<td>'+item.branchPrice+'</td>';
                    html+='<td>_status_desc</td>';
	            	 html+='<td>_status_result</td>';
	            	 html+='<td>_option_button</td></tr>';
            		 if(item.status=="1"){//草稿编辑
            			 if(item.isAllow=="1"&&item.workflowVo.isCurrtOpt=="1"){//允许分店,是否为当前操作人
            				html=html.replace("_option_href", '<a href="#"  onclick="updatePriceForBranchPage(this);"  pkPriceId='+item.pkPriceId+'  pkPrdId='+item.pkPrdId+'>'+item.pkPrdId+'</a>');
                		 	html=html.replace("_option_button", '<input type="button"  value="编辑" class="btn_l"   onclick="updatePriceForBranchPage(this);" pkPrdId='+item.pkPrdId+'   pkPriceId='+item.pkPriceId+' ><input type="button"   pkPriceId='+item.pkPriceId+'    onclick="deleteScmprdPrice(this);"    value="删除" class="btn_l ml10">');
            			 }else{
             				html=html.replace("_option_href", '<a href="#"   pkPriceId="'+item.pkPriceId+'"  pkPrdId="'+item.pkPrdId+'"   onclick="readBranchInfo(this);" >'+item.pkPrdId+'</a>');
                		 	html=html.replace("_option_button", '');
            			 }
            		 	html=html.replace("_status_desc", '草稿');
            		 	html=html.replace("_status_result", '');
            		 }else if(item.status=="2"){//待处理
            			 //退单
            			/*  if(obj2.isCurrtOpt=="1"&&obj2.isStartUser=="1"){ */
            				 if(item.isAllow=="1"&&obj2.isCurrtOpt=="1"&&obj2.isStartUser=="1"&&addFlagForBranch==true){
                				 html=html.replace("_option_href", '<a href="#"   onclick="updatePriceForBranchPage(this);"   pkPriceId='+item.pkPriceId+'   pkPrdId='+item.pkPrdId+'>'+item.pkPrdId+'</a>');
    						     html=html.replace("_option_button",'<input type="button"  value="重新申请" class="btn_l"  onclick="reSubmitForBranch(this);"   fkFlowinstId="'+item.fkFlowinstId+'"  pkPrdId="'+item.pkPrdId+'"    pkPriceId="'+item.pkPriceId+'" >');
                 		 	 }
            				 
            			/* 	 html=html.replace("_option_href", '<a href="#"   pkPriceId="'+item.pkPriceId+'"  pkPrdId="'+item.pkPrdId+'"   onclick="readBranchInfo(this);" >'+item.pkPrdId+'</a>');
    					     html=html.replace("_option_button", "<input type=\"button\" value=\"重新申请\"  onclick="">" ); */
            			else{
            				 html=html.replace("_option_href", '<a href="#"   pkPriceId="'+item.pkPriceId+'"  pkPrdId="'+item.pkPrdId+'"   onclick="readBranchInfo(this);" >'+item.pkPrdId+'</a>');
    					     html=html.replace("_option_button", '');
            			 }
            			html=html.replace("_status_desc", obj2.statusDesc);
            			html=html.replace("_status_result",obj2.result==null?"":obj2.result);
            		 }else if(item.status=="3"){//重新定价
            			 if(item.isAllow=="1"&&addFlagForBranch==true){
            				 html=html.replace("_option_href", '<a href="#"   branchPrice="'+item.branchPrice+'"   pkPrdId="'+item.pkPrdId+'"  pkPriceId="'+item.pkPriceId+'" onclick="reSetPriceForBranchPage(this);">'+item.pkPrdId+'</a>');
                			 html=html.replace("_option_button", '<input type="button"  value="重新定价" class="btn_l"   branchPrice="'+item.branchPrice+'"  pkPrdId="'+item.pkPrdId+'"  pkPriceId="'+item.pkPriceId+'" onclick="reSetPriceForBranchPage(this);"><input type="button" onclick="showHistoryForBranch(this);" pkPrdId="'+item.pkPrdId+'"    value="历史定价" class="btn_l ml10">');
            			 }else{
            				 html=html.replace("_option_href", '<a href="#"   pkPriceId="'+item.pkPriceId+'"  pkPrdId="'+item.pkPrdId+'"   onclick="readBranchInfo(this);" >'+item.pkPrdId+'</a>');
                			 html=html.replace("_option_button", '<input type="button" onclick="showHistoryForBranch(this);" pkPrdId="'+item.pkPrdId+'"    value="历史定价" class="btn_l ml10">');
            			 }
            			html=html.replace("_status_desc", obj2.statusDesc);
             			html=html.replace("_status_result", obj2.result==null?"":obj2.result);
            		 }else if(item.status=="4"){
            			 if(item.isAllow=="1" &&addFlagForBranch==true){
            				 html=html.replace("_option_href", '<a href="#"   branchPrice="'+item.branchPrice+'"   pkPrdId="'+item.pkPrdId+'"  pkPriceId="'+item.pkPriceId+'" onclick="reSetPriceForBranchPage(this);"   >'+item.pkPrdId+'</a>');
                			 html=html.replace("_option_button", '<input type="button"  value="重新定价" class="btn_l"   branchPrice="'+item.branchPrice+'"  pkPrdId="'+item.pkPrdId+'"  pkPriceId="'+item.pkPriceId+'" onclick="reSetPriceForBranchPage(this);"><input type="button" onclick="showHistoryForBranch(this);" pkPrdId="'+item.pkPrdId+'"    value="历史定价" class="btn_l ml10">');
            			 }else{
            				 html=html.replace("_option_href", '<a href="#"   pkPriceId="'+item.pkPriceId+'"  pkPrdId="'+item.pkPrdId+'"   onclick="readBranchInfo(this);" >'+item.pkPrdId+'</a>');
                			 html=html.replace("_option_button", '<input type="button" onclick="showHistoryForBranch(this);" pkPrdId="'+item.pkPrdId+'"    value="历史定价" class="btn_l ml10">');
            			 }
            			html=html.replace("_status_desc", obj2.statusDesc);
             			html=html.replace("_status_result", obj2.result==null?"":obj2.result);
            		 }else if(item.status=="5"){//关闭
            				 html=html.replace("_option_href", '<a href="#"   pkPriceId="'+item.pkPriceId+'"  pkPrdId="'+item.pkPrdId+'"   onclick="readBranchInfo(this);" >'+item.pkPrdId+'</a>');
							 html=html.replace("_option_button",'');
							 html=html.replace("_status_desc", obj2.statusDesc);
		            		 html=html.replace("_status_result", obj2.result==null?"":obj2.result);
            		 }else if(item.status==""){//未定价
            			 if(item.isAllow=="1"&&addFlagForBranch==true){//允许分店报价,有权限
            				 html=html.replace("_option_href", '<a href="#"   id='+item.pkPrdId+'   onclick="setPriceForBranch(this);" >'+item.pkPrdId+'</a>');
						     html=html.replace("_option_button",'<input type="button"  value="定价"   id='+item.pkPrdId+'   onclick="setPriceForBranch(this);"   class="btn_l">');
            			 }else{
            				 html=html.replace("_option_href", '<a href="#"   pkPriceId="'+item.pkPriceId+'"  pkPrdId="'+item.pkPrdId+'"   onclick="readBranchInfo(this);" >'+item.pkPrdId+'</a>');
						     html=html.replace("_option_button",'');
            			 }
            			html=html.replace("_status_desc", "");
             			html=html.replace("_status_result", "");
            		 }
		     	    $("#"+tableId).find("tr:eq("+index+")").after(html);
      			}); 	
            }
		}
		//删除定价的草稿信息
		function deleteScmprdPrice(thisObj){
			$.messager.confirm('警告', "你确定要删除该项纪录吗?", function(isOk) {
				if (isOk) {
					  var  pkPriceId=$(thisObj).attr("pkPriceId");
					  window.location.href="${basePath}scmInvocing/priceManager/deleteTempPrice.shtml?pkPriceId="+pkPriceId+"";
				}
			});
		}
		//重新提交
		function reSubmitForBranch(thisObj){
			var fkFlowinstId=$(thisObj).attr("fkFlowinstId");
			var pkPrdId=$(thisObj).attr("pkPrdId");
			var pkPriceId=$(thisObj).attr("pkPriceId");
			window.location.href="${basePath}scmInvocing/priceManager/reSubmitForBranchPage.shtml?pkPriceId="+pkPriceId+"&pkPrdId="+pkPrdId+"&fkFlowinstId="+fkFlowinstId+"";
		}
		
		//门店重新定价
		function reSetPriceForBranchPage(thisObj){
			var pkPriceId=$(thisObj).attr("pkPriceId");
			var 	pkPrdId=$(thisObj).attr("pkPrdId");
			var  branchPrice=$(thisObj).attr("branchPrice");
			window.location.href="${basePath}scmInvocing/priceManager/setPriceForBranch.shtml?pkPrdId="+pkPrdId+"&isReset="+pkPriceId+"&branchPrice="+branchPrice+"";
		}
		//总监审批门店递交过来定价信息
		function handleBranchPrice(thisObj){
			var  pkPriceId=$(thisObj).attr("pkPriceId");
			var  pkPrdId=$(thisObj).attr("pkPrdId");
			window.location.href="${basePath}scmInvocing/priceManager/handPriceForBranchPage.shtml?pkPriceId="+pkPriceId+"&pkPrdId="+pkPrdId+"";
		}
		
		//跳转到提交或重新提交页面,无历史
		function updatePriceForBranchPage(thisObj){
					var pkPrdId=$(thisObj).attr("pkPrdId");
					var pkPriceId=$(thisObj).attr("pkPriceId");
					window.location.href="${basePath}scmInvocing/priceManager/updatePriceForBranchPage.shtml?pkPrdId="+pkPrdId+"&pkPriceId="+pkPriceId+"";
			
		}
		//查询门店的定价信息
		function  readBranchInfo(thisObj){
			var pkPrdId=$(thisObj).attr("pkPrdId");
			var pkPriceId=$(thisObj).attr("pkPriceId");
			window.location.href="${basePath}scmInvocing/priceManager/readBranchInfo.shtml?pkPrdId="+pkPrdId+"&pkPriceId="+pkPriceId+"";
		}
		//门店定价
		function setPriceForBranch(thisObj){
			var pkPrdId=$(thisObj).attr("id");
			var fkBranId=$(".thistab_a").attr("id").split("_")[0];
			window.location.href="${basePath}scmInvocing/priceManager/setPriceForBranch.shtml?pkPrdId="+pkPrdId+"&fkBranId="+fkBranId+"";
		}
		//函数处理方法
	
		function  reSubmitForHead(obj){
				var pkPrdId=$(obj).attr("id");	
				window.location.href="${basePath}scmInvocing/priceManager/forwardToReSubmitHead.shtml?pkPrdId="+pkPrdId+"";
		}
		//重新定价或编辑
		function editForHead(obj){
			var pkPrdId=$(obj).attr("id");	
			var isNew=$(obj).attr("isNew");
			window.location.href="${basePath}scmInvocing/priceManager/forwardEditForHead.shtml?pkPrdId="+pkPrdId+"&isNew="+isNew+"";
		}
		//总部复核
		function  reviewPriceForHead(obj){
			var pkPrdId=$(obj).attr("id");	
			window.location.href="${basePath}scmInvocing/priceManager/reviewPriceForHead.shtml?pkPrdId="+pkPrdId+"";			
		}
		function setPriceForHead(obj){
			var pkPrdId=$(obj).attr("id");	
			window.location.href="${basePath}scmInvocing/priceManager/setPriceForHead.shtml?pkPrdId="+pkPrdId+"";
		}
	</SCRIPT>
<body class="bg">
<div class="content m_auto">
	<div class="content_l mt10">
    	<ul>
    		<shiro:hasPermission name="scmInvocing/productInfo/forwardToProductInfo.shtml">
    				  <li ><a href="${basePath}scmInvocing/productInfo/forwardToProductInfo.shtml"><i class="nav_icon_b"></i><br>商品信息</a></li>
    		</shiro:hasPermission>
    		 <shiro:hasPermission name="scmInvocing/countUnit/forwardToUnitInfo.shtml">
    		 		<li><a href="${basePath}scmInvocing/countUnit/forwardToUnitInfo.shtml"><i class="nav_icon_b"></i><br>单位设置</a></li>
    		 </shiro:hasPermission>
    		 <shiro:hasPermission name="scmInvocing/supplier/forwardToSupply.shtml">
    		 		   <li><a href="${basePath}scmInvocing/supplier/forwardToSupply.shtml"><i class="nav_icon_a"></i><br>供应商信息</a></li>
    		 </shiro:hasPermission>
    		  <shiro:hasPermission name="scmInvocing/priceManager/forwardToList.shtml">
    		 		  <li  class="content_hover"><a href="${basePath}scmInvocing/priceManager/forwardToList.shtml"><i class="nav_icon_f"></i><br>价格管理</a></li>
    		 </shiro:hasPermission>
    		   <shiro:hasPermission name="scmInvocing/scmPurOrder/findInvoPurOrder.shtml">
            	  <li><a href="${basePath}scmInvocing/scmPurOrder/findInvoPurOrder.shtml"><i class="nav_icon_b"></i><br>采购订单</a></li>
    		 </shiro:hasPermission>
    		   <shiro:hasPermission name="scmInvocing/scmPayForm/findInvoOrderPay.shtml">
           		   <li><a href="${basePath}scmInvocing/scmPayForm/findInvoOrderPay.shtml"><i class="nav_icon_b"></i><br>付款申请</a></li>
    		 </shiro:hasPermission>
  		 </ul>
    </div>
    <div class="content_r mt10">
    	<div class="p20">
    	<div class="file_single_dl f14 fixed">
        	<dl class="fixed fl">
            	<dd><label>商品编号：</label><input type="text" class="iput_t w200"  id="pkPrdId"/></dd>
                <dd><label>商品名称：</label><input type="text" class="iput_t w200" id="prdName"/></dd>
                <dd><input type="button" class="btn ml10" value="查询" onclick="findPriceInfo();"></dd>
            </dl>
        </div>
        <div class="tab_normalx  mt10">
            <div class="payment_l" style="width:240px !important;">
				<div class="ztree ztree_h" id="sptree"></div>
            </div>
            
            <div class="payment_rx tab_normal ">
            
            	<ul id="tab_a" class="fixed">
            	<c:choose>
            	<c:when test="${isHead=='1'}">
            		<c:forEach items="${branList}" var="item">
            			<c:if test="${item.abbrCode==headCode}">
									<li onclick="initTable(this);" id="${item.pkBranId}_Li" branChFlag="ZB">${item.branName}</li>
            			</c:if>
            		</c:forEach>
            	<c:forEach items="${branList}" var="item">
            			<c:if test="${item.abbrCode!=headCode}">
									<li onclick="initTable(this);" id="${item.pkBranId}_Li" branChFlag="FZB">${item.branName}</li>
            			</c:if>
                </c:forEach>         	
            	</c:when>
            	<c:otherwise>
            	<c:forEach items="${branList}" var="item">
									<li onclick="initTable(this);" id="${item.pkBranId}_Li">${item.branName}</li>
               	 </c:forEach>    
            	</c:otherwise>
            	</c:choose>
                </ul>
                 <ul id="tab_conbox_a" class="fixed ">
                 <c:choose>
                		<c:when test="${isHead=='1'}">
                			<c:forEach items="${branList}" var="item">
                <c:if test="${item.abbrCode==headCode}">
                		<li class="p10">
                		<form id="${item.pkBranId}Form" action="${basePath}scmInvocing/priceManager/getHeadInfo.shtml">
                       	<input type="hidden" name="pageNo" value="1"/>
    					<input type="hidden" name="pageSize" value="8"/>
    					<input type="hidden" name="pkPrdId" />
    					<input type="hidden" name="cateId" />
    					<input type="hidden" name="prdName" />
    					<input type="hidden" name="fkBranId" value="${item.pkBranId}">
                       	 <table class="table" id="${item.pkBranId}Table">
                            <tr>  
                                <th>商品编号</th>
                                <th>商品名称</th> 
                                <th>规格</th>
                                <th>计量单位</th> 
                                <th>市场销售价</th> 
                                <th>总部价格</th> 
                                <th>允许分店定价</th> 
                                <th>审批状态</th>
                                <th>操作</th>
                            </tr>
                        </table>
                        </form>
                        <div class="page fr m10" id="${item.pkBranId}Foot">
                            
                        </div>
                    	</li>		
                </c:if>	
                </c:forEach>
                		<c:forEach items="${branList}" var="item">
            					<c:if test="${item.abbrCode!=headCode}">
					<li class="p10">
						<form action="${basePath}scmInvocing/priceManager/getBranchInfo.shtml" id="${item.pkBranId}Form">
						<input type="hidden" name="pageNo" value="1">
    					<input type="hidden" name="pageSize" value="8">
    					<input type="hidden" name="cateId" />
    					<input type="hidden" name="fkBranId" value="${item.pkBranId}">
    					<input type="hidden" name="pkPrdId" />
    					<input type="hidden" name="prdName" />
                        <table class="table"  id="${item.pkBranId}Table">
                            <tr>  
                                <th>商品编号</th>
                                <th>商品名称</th> 
                                <th>规格</th>
                                <th>计量单位</th> 
                                <th>市场销售价</th> 
                                <th>总部价格</th> 
                                <th>允许分店定价</th> 
                                <th>分店价格</th> 
                                <th>审批状态</th>  
                                <th>审批结果</th>
                                <th>操作</th>
                            </tr>
                        </table>
                        </form>
                        <!----翻页----->
                        <div class="page fr m10"  id="${item.pkBranId}Foot">
                            
                        </div>
                    </li>
            	</c:if>
                </c:forEach>         						
                </c:when>
                <c:otherwise>
                <c:forEach items="${branList}" var="item">
                		<li class="p10">
                		<form id="${item.pkBranId}Form" action="${basePath}scmInvocing/priceManager/getBranchInfo.shtml">
                			<input type="hidden" name="pageNo" value="1">
    						<input type="hidden" name="pageSize" value="8">
    						<input type="hidden" name="cateId" />
    						<input type="hidden" name="fkBranId" value="${item.pkBranId}">
    						<input type="hidden" name="pkPrdId" />
    						<input type="hidden" name="prdName" />
                       	 <table class="table"  id="${item.pkBranId}Table">
                            <tr>  
                                <th>商品编号</th>
                                <th>商品名称</th> 
                                <th>规格</th>
                                <th>计量单位</th> 
                                <th>市场销售价</th> 
                                <th>总部价格</th> 
                                <th>允许分店定价</th> 
                                <th>分店价格</th> 
                                <th>审批状态</th>  
                                <th>审批结果</th>
                                <th>操作</th>
                            </tr>
                        </table>
                        </form>
                        <div class="page fr m10" id="${item.pkBranId}Foot" >
							
                        </div>
                 	   </li>
                	</c:forEach>
               </c:otherwise>
                </c:choose>
                </ul>
            </div>
		</div>
        </div>
    </div>
</div>
<!---弹出层 成员信息编w辑--->
<div id="historyHead" class="easyui-window" title="历史定价" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:900px; height:350px;position:relative;">
	
    <div class="p10">
    	<form id="historyForm" action="${basePath}scmInvocing/priceManager/findHistoryForHead.shtml">
    	<input type="hidden" name="pageNo" id="pageNoForHead" value="1">
    	<input type="hidden" name="pageSize" id="pageSizeForHead" value="8">
    	<input type="hidden" name="fkPrdId" id="fkPrdId" value="">
    	<dl class="fixed fl">
            <dd><label>商品名称：</label ><span id="headPrdName"></span></dd>
            <dd><label>规格：</label><span id="headPrdSpec"></span></dd>
            <dd><label>计量单位：</label><span id="headUnitName"></span></dd>
        </dl>
    	<table class="table m10" id="historyData">
            <tr>  
                <th>序号</th>
                <th>定价人</th>
                <th>市场销售价</th> 
                <th>总部价格</th> 
                <th>时间</th>
            </tr>
		</table>
		</form>
        <!----翻页----->
        <div class="page fr m10" id="foot">
            
        </div>
        <!----翻页----->
    </div>
    <div class="btm_btn btm_bg">
    	<dl>
        	<dd><input type="button" class="btn" onClick="$('#historyHead').window('close')" value="确定"></dd>
            <dd><input type="button" class="btn" onClick="$('#historyHead').window('close')" value="取消"></dd>
        </dl>
    </div>
</div>
<!---弹出层 成员信息编w辑--->
<div id="historyBranch" class="easyui-window" title="历史定价" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:900px; height:350px;position:relative;">
	<form action="${basePath}scmInvocing/priceManager/findHistoryForBranch.shtml" id="historyForBranch">
		<input type="hidden" name="pageNo" id="pageNo" value="1">
    	<input type="hidden" name="pageSize" id="pageSize" value="8">
    	<input type="hidden" name="fkPrdId" id="PrdId" value="">
	    <input type="hidden" name="fkBranId" id="fkBranId" value="">
	</form>
    <div class="p10">
    	<dl class="fixed fl">
            <dd><label>商品名称：</label><span id="prdNameForBranch" ></span></dd>
            <dd><label>规格：</label><span id="prdSpecForBranch"></span></dd>
            <dd><label>计量单位：</label><span id="unitNameForBranch"></span></dd>
        </dl>
    	<table class="table m10" id="historyBranchTable">
            <tr>  
                <th>序号</th>
                <th>定价人</th>
                <th>市场销售价</th> 
                <th>分店价格</th>
                <th>定价时间</th>
            </tr>
         </table>
        <!----翻页----->
        <div class="page fr m10" id="footForBranch">
           
         </div>
        <!----翻页----->
    </div>
    <div class="btm_btn btm_bg">
    	<dl>
        	<dd><input type="button" class="btn" onClick="$('#historyBranch').window('close')" value="确定"></dd>
            <dd><input type="button" class="btn" onClick="$('#historyBranch').window('close')" value="取消"></dd>
        </dl>
    </div>
</div>
</body>
</html>